<% layout('/layouts/default.html', {title: '田间管理信息管理', libs: ['validate']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(ownMedicineFieldManagement.isNewRecord ? '新增田间管理信息' : '编辑田间管理信息')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${ownMedicineFieldManagement}" action="${ctx}/own/ownMedicineFieldManagement/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<div class="row" id="info" hidden>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('种子种苗植物名')}：</label>
							<label class="col-sm-8" id="seednm"></label>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('种植批次码')}：</label>
							<label class="col-sm-8" id="plantpc"></label>
						</div>
					</div>
					<div class="col-xs-4">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">${text('种植时间')}：</label>
							<label class="col-sm-8" id="planttt"></label>
						</div>
					</div>
				</div>
				<#form:hidden path="id"/>
				<#form:hidden id="ownMedicinePlantInformationId" path="ownMedicinePlantInformationId"/>
				<#form:hidden id="bmBatchCode" path="bmBatchCode"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('种植批次号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:listselect id="batchId" title="种植批次号" labelPath="batchId"
								url="${ctx}/own/ownMedicinePlantInformation/findByKey" allowClear="false" checkbox="false"
								itemCode="batchId" itemName="batchId" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('管理名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="name" maxlength="50" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('管理类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="type" dictType="own_medicine_field_management_type" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group" id="fertilization" hidden>
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('施肥种类')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select id="sefertilization" path="specificType" dictType="own_medicine_field_management_fertilization_specific_type" blankOption="true" class="form-control required"/>
							</div>
						</div>
						<div class="form-group" id="pesticide" hidden>
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('农药种类')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select id="sepesticide" path="specificType" dictType="own_medicine_field_management_pesticide_specific_type" blankOption="true" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row" id="extend" hidden>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('种类名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="specificName" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('用量(kg/亩)')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="weight" class="form-control number required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('操作时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="addTime" readonly="true" maxlength="20" class="form-control Wdate required"
									dataFormat="date" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('own:ownMedicineFieldManagement:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
//选择种植批次号回调方法
function  listselectCallback(id, act, index, layero, selectData) {
	if (id == 'batchId' && (act == 'ok' || act == 'clear')){
		for (let key in selectData){
			$('#ownMedicinePlantInformationId').val(selectData[key]['id']);
			$('#bmBatchCode').val(selectData[key]['bmBatchCode']);
			$("#seednm").text(selectData[key].varietyName);
			$("#plantpc").text(selectData[key].bmBatchCode);
			$("#planttt").text(selectData[key].plantTime);
			$("#info").show();
			break;
		}
	}
}
$("input:radio[name='type']").on('ifChecked', function(event){
	var value = $(this).val();
	$("#specificName").val("");
	$("#weight").val("");
	if (value == "施肥" || value == "农药"){
		$("#extend").show();
		$("#specificName").addClass("required");
		$("#weight").addClass("required");
		if (value == "施肥"){
			$("#sefertilization").addClass("required");
			$("#sepesticide").removeClass("required");
			$("#fertilization").show();
			$("#pesticide").hide();
		}
		if (value == "农药"){
			$("#sepesticide").addClass("required");
			$("#sefertilization").removeClass("required");
			$("#fertilization").hide();
			$("#pesticide").show();
		}
	}else {
		$("#sefertilization").removeClass("required");
		$("#sepesticide").removeClass("required");
		$("#specificName").removeClass("required");
		$("#weight").removeClass("required");
		$("#fertilization").hide();
		$("#pesticide").hide();
		$("#extend").hide();
	}
});
$("#sefertilization").change(function() {
	var value = $(this).val();
	if (value != "其它"){
		$("#specificName").val(value);
	}else {
		$("#specificName").val("");
	}
});
$("#sepesticide").change(function() {
	var value = $(this).val();
	if (value != "其它"){
		$("#specificName").val(value);
	}else {
		$("#specificName").val("");
	}
});
$(function(){
	var jsss = "${ownMedicineFieldManagement.isNewRecord}"; //获取beetl的值
	if (jsss == 'false'){
		$("#batchIdName").attr("disabled","disabled");
		$("#info").show();
	}
	var val = "${ownMedicineFieldManagement.type}";
	if (val == "施肥" || val == "农药"){
		$("#extend").show();
		if(val == "施肥"){
			$("#fertilization").show();
		}else {
			$("#pesticide").show();
		}
	}
	$.ajax({
		url: "${ctx}/own/ownMedicinePlantInformation/findById",
		type: "get",
		data: {"id": "${ownMedicineFieldManagement.ownMedicinePlantInformationId}"},
		dataType: "json",
		success: function (data) {
			if (data.ownMedicinePlantInformation){
				$("#seednm").text(data.ownMedicinePlantInformation.varietyName);
				$("#plantpc").text(data.ownMedicinePlantInformation.bmBatchCode);
				$("#planttt").text(data.ownMedicinePlantInformation.plantTime);
			}else {
				js.showErrorMessage("获取错误！", data.msg);
			}
		},
		error: function (e) {
			js.showErrorMessage("错误", e);
		}
	});
});
</script>